/**
 * 
 */
package com.njmd.mdbs.web.security;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.google.common.base.Objects;
import com.njmd.mdbs.web.entity.sys.SysCorp;
import com.njmd.mdbs.web.entity.sys.SysLogin;
import com.njmd.mdbs.web.entity.sys.SysPermission;
import com.njmd.mdbs.web.entity.sys.SysRole;

/**
 * @title: 系统登录令牌类
 * 
 * @description: 用户登录后，该用户的所有信息将通过该对象保存至用户会话中
 * 
 * @author: Yao
 */
public class LoginToken implements Serializable
{
	private static final long serialVersionUID = -4926293702502367333L;

	// 登录信息
	private SysLogin loginInfo;
	
	// 单位信息
	private SysCorp corpInfo;
	
	// 角色信息
	private List<SysRole> roles;

	// 菜单权限
	private Map<Long, SysPermission> permissions;

	public LoginToken()
	{

	}

	public LoginToken(SysLogin sysLogin)
	{
		this.loginInfo = sysLogin;
	}

	public SysLogin getLoginInfo()
	{
		return loginInfo;
	}

	public void setLoginInfo(SysLogin loginInfo)
	{
		this.loginInfo = loginInfo;
	}

	public SysCorp getCorpInfo()
	{
		return corpInfo;
	}

	public void setCorpInfo(SysCorp corpInfo)
	{
		this.corpInfo = corpInfo;
	}

	public List<SysRole> getRoles()
	{
		return roles;
	}

	public void setRoles(List<SysRole> roles)
	{
		this.roles = roles;
	}

	public Map<Long, SysPermission> getPermissions()
	{
		return permissions;
	}

	public void setPermissions(Map<Long, SysPermission> permissions)
	{
		this.permissions = permissions;
	}

	/**
	 * 本函数输出将作为默认的<shiro:principal/>输出.
	 */
	@Override
	public String toString()
	{
		return loginInfo.getLoginName();
	}

	/**
	 * 重载hashCode,只计算loginName;
	 */
	@Override
	public int hashCode()
	{
		return Objects.hashCode(loginInfo.getLoginName());
	}

	/**
	 * 重载equals,只计算loginName;
	 */
	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
		{
			return true;
		}
		if (obj == null)
		{
			return false;
		}
		if (getClass() != obj.getClass())
		{
			return false;
		}
		LoginToken other = (LoginToken) obj;
		if (this.loginInfo.getLoginName() == null)
		{
			if (other.getLoginInfo().getLoginName() != null)
			{
				return false;
			}
		}
		else if (!this.loginInfo.getLoginName().equals(other.getLoginInfo().getLoginName()))
		{
			return false;
		}
		return true;
	}
}
